<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .main {
        display: none;
        /* position: absolute; */
        position: fixed;
        width: 300px;
        height: 200px;
        background-color: rgba(178, 184, 190, 0.523);
        transform: translate(-50%, -50%);
        left: 50%;
        top: 50%;
        border: solid 1px;
        z-index: 9999;
    }

    .login {
        font-size: 30px;
        width: 200px;
        border: solid 1px;
    }

    .bg {
        display: none;
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0px;
        left: 0px;
        background: rgba(0, 0, 0, 0.3);
        z-index: 1;
    }

    .close {
        width: 40px;
        height: 40xp;
        /* z-index: 9999; */
        /* float: left; */
        z-index: 9999;
    }

    .title {
        /* float: left; */
        height: 40px;
        border: solid 1px;
        z-index: 9999;
    }
</style>

<body>
    <!-- 登录框 -->
    <div class="main">
        <div class="title">

        </div>
        <div class="close">
            <a href="javascript:;">关闭</a>
        </div>
    </div>
    <!-- 点击登录按钮 -->
    <div class="login">
        点击登录
    </div>
    <!-- 背景框 -->
    <div class="bg"></div>
    <script>
        var main = document.querySelector('.main');
        var title = document.querySelector('.title');
        var close = document.querySelector('.close');
        var login = document.querySelector('.login');
        var bg = document.querySelector('.bg');
        login.addEventListener('click', function () {
            main.style.display = 'block';
            bg.style.display = 'block';
            this.style.display = 'none';
        });
        close.addEventListener('click', function () {
            main.style.display = 'none';
            bg.style.display = 'none';
            login.style.display = 'block';
        });
        title.addEventListener('mousedown', function (e) {
            // 获取鼠标在盒子内的相对位置
            var x = e.pageX - main.offsetLeft;
            var y = e.pageY - main.offsetTop;

            function move(e) {
                main.style.left = e.pageX - x + 'px';
                main.style.top = e.pageY - y + 'px';
                document
            }
            document.addEventListener('mousemove', move)
            document.addEventListener('mouseup', function () {
                document.removeEventListener('mousemove', move);
            })
        });
    </script>
</body>

</html>